package com.hitrust.gs.action;

import java.util.ArrayList;
import java.util.HashMap;

import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.business.GSBalanceProcessor;
import com.hitrust.gs.business.GSOrderDeptInfoProcessor;
import com.hitrust.gs.form.GSBalanceDetlOptForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.vo.GSUnBalanceDetailOptVO;

public class GSUnBalanceDetailNotBalanceAction extends GSBaseAction {

	public String execute(GSBaseForm aForm) throws Exception {
		GSBalanceDetlOptForm tForm = (GSBalanceDetlOptForm)aForm;
		GSUnBalanceDetailOptVO tVO = new GSUnBalanceDetailOptVO();
		try{
			tVO.balanceYM = tForm.getBalanceYM1();
			tVO.deptCategory = tForm.getDeptCategory1();
			tVO.deptId = tForm.getDeptId1();
			if(tForm.getIndex() != null&& tForm.getIndex().length > 0){
				tVO.orderDetailIds = new ArrayList();
				for(int i=0; i<tForm.getIndex().length;i++){
					if(tForm.getIndex()[i] != null){
						tVO.orderDetailIds.add(tForm.getIndex()[i]);
					}
				}
			}
			//取得当前操作员可查询的订货单位和送货地址
	        GSOperatorBean tOperBean = (GSOperatorBean)aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
	        GSOrderDeptInfoProcessor tOrderDeptProc = new GSOrderDeptInfoProcessor();
	        HashMap tMap = tOrderDeptProc.getOrderDeptInfoOfBusOper(tOperBean.getGs_oper_org_id());
	        aForm.getRequest().setAttribute("orderdept",tMap);
			GSBalanceProcessor tBalProc = new GSBalanceProcessor();
			//执行暂不结算
			boolean tFlag = tBalProc.tempUnBalance(tVO,tOperBean);
			if(tFlag){
				tForm.getRequest().setAttribute("message","共"+tVO.orderDetailIds.size() + "笔暂不结算执行成功！");
			}else{
				tForm.getRequest().setAttribute("message","共"+tVO.orderDetailIds.size() + "笔暂不结算执行失败！");
			}
			tForm.getRequest().setAttribute("requery","true");
            tForm.getRequest().setAttribute("deptId",tVO.deptId);
            tForm.getRequest().setAttribute("deptCategory",tVO.deptCategory);
            tForm.getRequest().setAttribute("balanceYM",tVO.balanceYM);
		}catch(Exception e){
			tForm.getRequest().setAttribute("window","true");
			throw e;
		}
		return GSBaseConstants.FORWARD_SUCCESS;
	}

}
